package cn.shop.admin.service.message.impl;

import cn.shop.admin.service.message.MessageUtil;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author : 李一涵
 * @date : Created in 2022/5/28 14:59
 * @description :
 */
@Service
@ConditionalOnExpression("'${spring.profiles.active:dev}' != 'online'")
public class RocketMessageUtil implements MessageUtil {

    private final static Logger LOG = LoggerFactory.getLogger(RocketMessageUtil.class);

    @Resource
    private RocketMQTemplate template;

    @Override
    public <T> void sendMessage(String topic, String tag, T t) {
        LOG.info("发送rocket消息：topic={}, tag={}, body={}", topic, tag, t);
        template.syncSend(topic + ":" + tag, t);
    }

}
